//
//  ByProductCommentListVC.m
//  mijifen_ios
//
//  Created by 朱凯 on 2017/11/2.
//  Copyright © 2017年 itboye. All rights reserved.
//

#import "ByProductCommentListVC.h"

// view
#import "ByViewProductCommentListHeader.h"          // 评论头视图

// cell
#import "ByCellProductCommentListItem.h"            // 评价

@interface ByProductCommentListVC () <UITableViewDelegate, UITableViewDataSource>

@property (nonatomic, strong) UITableView *table;

@end

@implementation ByProductCommentListVC

#pragma mark - view method
- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title = @"商品评价";
    
    [self addLeftBackBarButtonItem];
    
    [self createViews];
}


#pragma mark - 创建视图
- (void)createViews {
    
    // 标示图
    self.table = [[UITableView alloc] init];
    self.table.backgroundColor = BY_BG_COLOR;
    self.table.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.table.delegate = self;
    self.table.dataSource = self;
    [self.view addSubview:self.table];
    [self.table mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.view).insets(UIEdgeInsetsMake(0, 0, 0, 0)).priorityMedium();
        if (@available(iOS 11.0, *)) {
            make.bottom.equalTo(self.view.mas_safeAreaLayoutGuideBottom).offset(-0);
            make.left.equalTo(self.view.mas_safeAreaLayoutGuideLeft);
            make.right.equalTo(self.view.mas_safeAreaLayoutGuideRight);
        }
    }];
    
    [self.table registerClass:[ByCellProductCommentListItem class] forCellReuseIdentifier:@"commentCell"];
    
    [self.table registerClass:[ByViewProductCommentListHeader class] forHeaderFooterViewReuseIdentifier:@"commentHeader"];
    
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    
    return _detailModel.comments.count;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    return 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    ByCellProductCommentListItem *cell = [tableView dequeueReusableCellWithIdentifier:@"commentCell"];
    cell.model = _detailModel.comments[indexPath.section];
    return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {

    return [tableView fd_heightForCellWithIdentifier:@"commentCell" cacheByIndexPath:indexPath configuration:^(ByCellProductCommentListItem *cell) {
        cell.model = _detailModel.comments[indexPath.section];
    }];
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    
    if (section == 0) {
        return 40;
    }
    return 0;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    
    if (section == 0) {
        
        ByViewProductCommentListHeader *header = (ByViewProductCommentListHeader *)[tableView dequeueReusableHeaderFooterViewWithIdentifier:@"commentHeader"];
        header.model = _detailModel;
        return header;
    }
    return [UIView new];
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return 10;
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
    return UIView.new;
}


@end
